/**
 * 
 */
package hihocoder;

import java.util.Scanner;

/**
 * @author zhongfang
 *
 */
public class 共同富裕 {

	/**
	 * n<=10^5,a[i]<=10^5，sum<=10^10超过int范围 注意
	 * 
	 * @param a
	 * @return
	 */
	public static long increseToSame(int[] a) {
		long totalStep = 0;
		int min = Integer.MAX_VALUE;
		long sum = 0;
		int n = a.length;
		for (int i = 0; i < n; i++) {
			min = Math.min(min, a[i]);
			sum += a[i];
		}
		totalStep = (sum - n * min);
		return totalStep;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int A[] = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = scanner.nextInt();
		}
		scanner.close();
		System.out.println(increseToSame(A));
	}

}
